/*
 *  jOTR - Java Off-The-Record Messaging Library
 *  Copyright (C) 2007 Markus Karnik
 *
 *  This program is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 3 of the License, 
 *  or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 *  for more details.
 *
 *  You should have received a copy of the GNU General Public License along 
 *  with this program; if not, see <http://www.gnu.org/licenses/>.
 *  
 */

package de.karnik.libjotr;

/**
 * This class implements the jotr protocol exception to handle protocol errors.
 * 
 * @author Markus Karnik - markus.karnik@my-design.org
 * @version 1.0
 * @since 1.0
 */
public class JotrProtocolException extends Exception {

	/**
	 * The undefined error type.
	 */
	public static final int UNDEFINED = 0;
	/**
	 * The unreadable message received error type.
	 */
	public static final int UNREADABLE_MSG_RECV = 1;
	/**
	 * The malformed data message received error type.
	 */
	public static final int MALFORMED_DATA_MSG_RECV = 2;
	
	/**
	 * Serial Version UID!
	 */
	private static final long serialVersionUID = 7816665697491050186L;
	
	/**
	 * The excption type.
	 */
	private int type = UNDEFINED;
	/**
	 * The local message to display.
	 */
	private String localMessage = null;
	/**
	 * The message to display to the remote user.
	 */
	private String remoteMessage = null;
	
	/**
	 * Constructs a jotr protocol exception from the fiven type.
	 * 
	 * @param type The exception type.
	 */
	public JotrProtocolException( int type ) {
		this.type = type;
		setMessages();
	}
	
	/**
	 * Creates messages depending on the exception type. 
	 */
	private void setMessages() {
		
		switch( type ) {
			case UNREADABLE_MSG_RECV:
				localMessage = "Unreadable encrypted Message was received!";
				remoteMessage = "You transmitted a unreadable encrypted Message!";
				break;
			case MALFORMED_DATA_MSG_RECV:
				localMessage = "We received a malformed Data Message!";
				remoteMessage = "You transmitted a malformed Data Message!";
				break;
		}
		
		
	}
	
	/**
	 * Returns the text for the remote message.
	 * 
	 * @return The text for the remote message.
	 */
	public String getRemoteMessage() {
		return remoteMessage;
	}
	
	/**
	 * Returns the text for the exception message.
	 * 
	 * @return The text for the exception message.
	 */
	public String getMessage() {
		return localMessage;
	}
	
	public String getLocalMessage() {
		return localMessage;
	}

	/**
	 * Returns the text for the local message.
	 * 
	 * @return The text for the local message.
	 */
	public int getType() {
		return type;
	}
	
}
